package com.jeethink.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.jeethink.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.jeethink.system.domain.InfoEvaluate;
import com.jeethink.system.mapper.InfoManagementMapper;
import com.jeethink.system.domain.InfoManagement;
import com.jeethink.system.service.IInfoManagementService;
import com.jeethink.common.core.text.Convert;

/**
 * 信息系统管理Service业务层处理
 * 
 * @author jeethink
 * @date 2022-09-19
 */
@Service
public class InfoManagementServiceImpl implements IInfoManagementService 
{
    @Autowired
    private InfoManagementMapper infoManagementMapper;

    /**
     * 查询信息系统管理
     * 
     * @param infoId 信息系统管理ID
     * @return 信息系统管理
     */
    @Override
    public InfoManagement selectInfoManagementById(Long infoId)
    {
        return infoManagementMapper.selectInfoManagementById(infoId);
    }

    /**
     * 查询信息系统管理列表
     * 
     * @param infoManagement 信息系统管理
     * @return 信息系统管理
     */
    @Override
    public List<InfoManagement> selectInfoManagementList(InfoManagement infoManagement)
    {
        return infoManagementMapper.selectInfoManagementList(infoManagement);
    }

    /**
     * 新增信息系统管理
     * 
     * @param infoManagement 信息系统管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertInfoManagement(InfoManagement infoManagement)
    {
        int rows = infoManagementMapper.insertInfoManagement(infoManagement);
        insertInfoEvaluate(infoManagement);
        return rows;
    }

    /**
     * 修改信息系统管理
     * 
     * @param infoManagement 信息系统管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateInfoManagement(InfoManagement infoManagement)
    {
        infoManagementMapper.deleteInfoEvaluateByInfoId(infoManagement.getInfoId());
        insertInfoEvaluate(infoManagement);
        return infoManagementMapper.updateInfoManagement(infoManagement);
    }

    /**
     * 删除信息系统管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteInfoManagementByIds(String ids)
    {
        infoManagementMapper.deleteInfoEvaluateByInfoIds(Convert.toStrArray(ids));
        return infoManagementMapper.deleteInfoManagementByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除信息系统管理信息
     * 
     * @param infoId 信息系统管理ID
     * @return 结果
     */
    @Override
    public int deleteInfoManagementById(Long infoId)
    {
        infoManagementMapper.deleteInfoEvaluateByInfoId(infoId);
        return infoManagementMapper.deleteInfoManagementById(infoId);
    }

    /**
     * 新增系统评价信息
     * 
     * @param infoManagement 信息系统管理对象
     */
    public void insertInfoEvaluate(InfoManagement infoManagement)
    {
        List<InfoEvaluate> infoEvaluateList = infoManagement.getInfoEvaluateList();
        Long infoId = infoManagement.getInfoId();
        if (StringUtils.isNotNull(infoEvaluateList))
        {
            List<InfoEvaluate> list = new ArrayList<InfoEvaluate>();
            for (InfoEvaluate infoEvaluate : infoEvaluateList)
            {
                infoEvaluate.setInfoId(infoId);
                list.add(infoEvaluate);
            }
            if (list.size() > 0)
            {
                infoManagementMapper.batchInfoEvaluate(list);
            }
        }
    }
}
